package com.netease.nie.service;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.netease.nie.base.cache.redis.Redis;
import com.netease.nie.common.CommonService;
import com.netease.nie.constants.CachePrefixConstants;
import com.netease.nie.dao.DrawLotterySettingDao;
import com.netease.nie.model.DrawLotterySetting;

/**
 * 抽奖入口配置业务服务接口实现
 * @author gzlibingjie
 */
@Service
public class DrawLotterySettingServiceImpl extends CommonService implements DrawLotterySettingService {
	
	@Resource
	private DrawLotterySettingDao drawLotterySettingDao;
	
	@Autowired
	private Redis redis;
	
	private static final String DRAW_LOTTERY_SETTING = CachePrefixConstants.DrawLotteryPrefix.DRAW_LOTTERY_SETTING;
	
	/**
	 * 获取抽奖活动入口配置
	 * @return 抽奖活动入口配置
	 */
	@Override
	@Transactional(readOnly = true)
	public DrawLotterySetting query() {
		String key = DRAW_LOTTERY_SETTING;
		DrawLotterySetting drawLotterySetting = null;
		if (redis.exists(key)) {
			drawLotterySetting = redis.get(key, DrawLotterySetting.class);
		} else {
			drawLotterySetting = drawLotterySettingDao.query();
			if (drawLotterySetting != null) {
				redis.set(key, drawLotterySetting);
			}
		}
		return drawLotterySetting;
	}

}
